package com.dommy.tab.adapter;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.dommy.tab.fragment.ContactFragment;
import com.dommy.tab.fragment.MsgContentFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * no use
 */
public class MsgContentFragmentAdapter extends FragmentPagerAdapter {
    private List<String> names;
    public static  int value = 0;
    public MsgContentFragmentAdapter(FragmentManager fm) {
        super(fm);
        this.names = new ArrayList<>();
    }

    /**
     * 数据列表
     *
     * @param datas
     */
    public void setList(List<String> datas) {
        this.names.clear();
        this.names.addAll(datas);
        notifyDataSetChanged();
    }

    @Override
    public long getItemId(int position) {
        return super.getItemId(position);
    }

    @Override
    public Fragment getItem(int position) {
        MsgContentFragment fragment = new MsgContentFragment();
        Bundle bundle = new Bundle();
        bundle.putString("name", " ");
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public int getCount() {
        return names.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        String plateName = names.get(position);
        if (plateName == null) {
            plateName = "";
        } else if (plateName.length() > 15) {
            plateName = plateName.substring(0, 15) + "...";
        }
        return plateName;
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        setValue(position);
//        System.out.println("wo shi ....................."+ ContactFragment.value);
        super.setPrimaryItem(container, position, object);
    }
    private static void setValue(int val){
        if(ContactFragment.value == val){
        }else{
            ContactFragment.value = val;
            ContactFragment.getWaterTwoHandler().sendEmptyMessageDelayed(1,100);
        }
    }

}
